/**
 * Created by jihb on 4/22/16.
 */
Ext.define('JYnovel.view.system.MenuForm',{
    extend:'Ext.form.Panel',
    alias:'widget.MenuForm',
    layout:'anchor',
    border:false,
    defaults:{
        type:'textfield',
        anchor:'100%',
        padding:5
    },
    initComponent:function () {
        var me = this;
        var loader= ExtCreateLoader({
            url:getUrl('/menu/detail'),
            autoLoad:false,
            ajaxOptions:{
                method:'GET'
            },
        },function (data) {
            if (data){
                me.down('textfield[name=name]').setValue(data.name);
                me.down('textfield[name=path]').setValue(data.path);
                me.down('textareafield[name=remark]').setValue(data.remark);
                me.down('hiddenfield[name=level]').setValue(data.level);
                me.down('hiddenfield[name=id]').setValue(data.id);
            }
        },true);
        Ext.applyIf(this,{
            loader:loader,
            items:[{
                xtype:'textfield',
                labelWidth:60,
                fieldLabel:'名称',
                name:'name',
                allowBlank:false,
                maxLength:50,
                maxLengthText:'最多50个字符'
            },{
                xtype:'textfield',
                labelWidth:60,
                fieldLabel:'路径',
                name:'path',
                allowBlank:false
            },{
                xtype:'textareafield',
                labelWidth:60,
                fieldLabel: '简介',
                name:'remark',
                maxLength:100,
                maxLengthText:'最多100个字符'
            },{
                xtype:'hiddenfield',
                name: 'level'
            },{
                xtype:'hiddenfield',
                name:'id'
            },{
                xtype:'hiddenfield',
                value:0,
                name:'parentId'
            }],
            buttons:[{
                text:'确定',
                name:'addMenuOkBtn',
                formBind:true
            }]
        });
        this.callParent(arguments);
    },
    /**
     * 显示form
     * @param title
     */
    showFormWin:function (title,id) {
        Ext.create('Ext.window.Window',{
            modal:true,
            title:title,
            layout:'fit',
            width:400,
            height:240,
            items:this
        }).show();
        if(id){
            this.getLoader().load({
                params:{
                    id:id
                }
            });
        }
    },
    /**
     * 关闭form
     */
    closeFormWin:function(){
        this.up('window').destroy();
    }
});